<?php
/*
 * @Create By: Vscode
 * @Author: falcon
 * @Date: 2021-02-15 23:18:25
 * 改订单销售员 纠正为正确的 销售员
 */
namespace application\controller;

use application\depend\Applog;
use application\model\PdoModel;
class Fix{

    public function main(){
        $sql = "select * from order_info where salesman='方曼琪' group by order_number";
        $orderRes = PdoModel::selectData($sql,[],'错误销售员的订单集合');

        if(!empty($orderRes)){
            foreach($orderRes as $v){
                $order_num = $v['order_number'];
                // 用订单号去主表查正确的销售员
                $sql1 = "select salesman from `order` where order_number='$order_num' limit 1";
                $res1 = PdoModel::selectData($sql1,[],'11');
                $realSalesman = $res1[0]['salesman'];
                $sql = "update order_info set salesman='{$realSalesman}' where order_number='{$order_num}'";
                if(false === PdoModel::selectData($sql,[],'更新订单详情的销售员')){
                    Applog::errorLog(['title'=>'更新订单详情的销售员','sql'=>$sql,'date'=>date('Ymd His')]);
                    return '更新订单详情的销售员出错!'.PHP_EOL;
                }
            }// foreach

            return '更新成功！'.PHP_EOL;
        }// if

        return '查不到销售员为方曼琪的订单！'.PHP_EOL;
    }// func

}// class